package com.wuyan.locationdog.util;

import java.util.Calendar;
import java.util.Date;

public class HourMinuteConverter {

    public static String convertToHourMinute(double hours) {
        int intHours = (int) hours; // 取整小时
        int minutes = (int) ((hours - intHours) * 60); // 计算分钟
        System.out.println(intHours + " hours and " + minutes + " minutes");

        return intHours + "小时" + minutes + "分钟";
    }

    /**
     * 获取传入日期所在月的第一天
     */
    public static Date firstDayDateOfMonth(final Date date) {

        final Calendar cal = Calendar.getInstance();

        cal.setTime(date);

        final int last = cal.getActualMinimum(Calendar.DAY_OF_MONTH);

        cal.set(Calendar.DAY_OF_MONTH, last);

        return cal.getTime();

    }

    /**
     * 获取传入日期所在月的最后一天
     */
    public static Date lastDayOfMonth(final Date date) {

        final Calendar cal = Calendar.getInstance();

        cal.setTime(date);

        final int last = cal.getActualMaximum(Calendar.DAY_OF_MONTH);

        cal.set(Calendar.DAY_OF_MONTH, last);

        return cal.getTime();

    }


    public static String frontZeroString(int day) {

        if (day < 10) {
            return "0" + day;
        }
        return day + "";
    }

    public static String convertSecondsToMinutesAndSeconds(int seconds) {
        int minutes = seconds / 60;
        int remainingSeconds = seconds % 60;
        return String.format("%02d:%02d", minutes, remainingSeconds);
    }
}
